package com.example.activitytest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ChildActivity extends Activity {
	int a = 0;
	private Button addA;
	private Button back;
	private TextView showA;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_child);
		
		showA = (TextView)findViewById(R.id.showA);
		addA = (Button)findViewById(R.id.addA);
		back = (Button)findViewById(R.id.back);
		
		Bundle bundle=getIntent().getExtras();
		a = bundle.getInt("VAL_OF_A");
		Log.d("Child onCreate", "hahaha "+a);
		showA.setText(Integer.toString(a));
		
		addA.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				a++;
				showA.setText(Integer.toString(a));
				Log.d("Child onClick", "hahaha "+a);
			}
		});
		back.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Log.d("ChildActivity", "hahaha setResult"+a);
				//setResult(a);
				Intent intent = getIntent();
				Bundle bundle = new Bundle();
				bundle.putInt("VAL_OF_A_C", a);
				intent.putExtras(bundle);
				setResult(RESULT_OK, intent);
				finish();
			}
		});
	}



}
